﻿@{
    ViewData["Title"] = "修改密码";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css{
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }

        .layui-form-item .layui-input {
            width: 350px;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
}
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧密码</label>
                <div class="layui-input-block">
                    <input type="password" name="oldPassword" lay-verify="required" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码" value="" class="layui-input">
                    <tip>填写自己账号的旧的密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="newPassword" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">确认新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="confirmPassword" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
@section js{
    <script>
        layui.use(['form', 'common', 'layer', 'jquery'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.jquery,
                apiUtil = layui.common;
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                if (data.field.newPassword !== data.field.confirmPassword) {
                    layer.msg('新密码两次输入不一样');
                    return false;
                }
                data.field.id = apiUtil.getCurrentUser().id;
                apiUtil.ajax('user/modfiyPwd', data.field, "application/json", "post", function (res) {
                    if (res.statusCode == 200 && res.success == true) {
                        setTimeout(function () {
                            $.ajax({
                                url: "/user/Logout",
                                type: "get",
                                success: function (res) {
                                    layer.msg('密码修改成功，即将退出,重新登陆...', function () {
                                        window.location = '/user/login';
                                    });
                                }
                            });
                        }, 1000);
                    } else {
                        apiUtil.error(res.msg);
                    }
                });
                return false;
            });

        });
    </script>
}

